<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<%@include file="../../commons/meta.jsp"%>
<link rel="stylesheet" href="${ctx}assets/plugins/pure/pure-min.css" media="all" />
<script type="text/javascript" src="${ctx}assets/plugins/plupload/2.2.1/js/plupload.full.min.js"></script>
<script type="text/javascript" src="${ctx}assets/plugins/plupload/2.2.1/js/i18n/zh_CN.js"></script>
<script type="text/javascript">
  debugs("${ctx} --- newscenter-add.jsp");
  function validateForm() {
    if (empty($("#majorTypeCode").val())) {
      alertError('请输入专业分类代码！');
      return false;
    }
    if(isNaN($("#majorTypeCode").val())){
      alertError('专业分类代码，请输入数字！');
      return false;
    }
    if (empty($("#majorTypeName").val())) {
      alertError('请输入专业分类名称！');
      return false;
    }
    if (empty($("#majorSubject").val())) {
      alertError('请选择上级专业分类！');
      return false;
    }
    $("#forms").submit();
  }
  //  关闭弹出框 
  jQuery(document).ready(function() {
    $("#back_btn").click(function() {
      window.location.href = "${ctx}api/major-types/"
    });
  });
</script>
</head>
<body>
    <%@include file="../../commons/head.jsp"%>
    <div class="content">
        <%@include file="../../commons/menu.jsp"%>
        <!--右侧展示部分-->
        <div class="right-zq">
            <!--center content-->
            <div class="dynamic">
                <div class="role dynamiclayer" style="display: block;">
                    <div class="title orange2">
                        <span class="left">专业管理</span> <label> > </label> <span>专业分类管理</span> <label> > </label> <span>修改</span>
                    </div>
                    <form class="" id="forms" method="post" action="${ctx}api/major-types/update">
                        <div class="news-table">
                            <table>
                                <tr>
                                    <td class="item">专业分类代码:</td>
                                    <td width="40%"><input class="p50" id="majorTypeCode" name="majorTypeCode" type="text" placeholder="" value="${obj.majorTypeCode}" /></td>
                                </tr>
                                <tr>
                                    <td class="item">专业分类名称:</td>
                                    <td width="40%"><input class="p50" id="majorTypeName" name="majorTypeName" type="text" placeholder="" value="${obj.majorTypeName}" /></td>
                                </tr>
                                <tr>
                                    <td class="item">上级专业分类:</td>
                                    <td width="40%">
                                    <select id="majorSubject" name="parentCode" class="input1" placeholder=""
                                        style="text-align: center;" >
                                    </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <input type="hidden" name="id" value="${obj.id}" />
                                    </td>
                                    <td>
                                        <button class="orange2" type="button" onclick="validateForm()">保存&nbsp;<i class="fa fa-floppy-o"></i>
                                        </button> &nbsp;&nbsp;
                                        <button class="orange2" type="button" id="back_btn">返回&nbsp;<i class="fa fa-undo"></i>
                                        </button>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </form>
                </div>
            </div>
            <!--center content over-->
        </div>
    </div>
    <%@include file="../../commons/footpop.jsp"%>
    <!-- 页尾，提示消息 -->
    <jsp:include page="../../commons/foot_message.jsp"></jsp:include>
<script type="text/javascript">
// 初始化时加载学科下拉框数据
getMajorSubject();
/**
 * 获取学科
 * @returns
 */
function getMajorSubject() {
  // 修改之前的上级分类代码。
  var parentCode = '${obj.parentCode}';
  
  // 默认按id排序
  var query = {};
  // 学科的父级代码默认为"00"
  query.parentCode = "00";
  var searchJsonUrl = 'api/major-types/findAll';
  var param = JSON.stringify(query);

  $.ajax({
   url: searchJsonUrl,
   data: param,
   type: 'POST',
   contentType: "application/json",
   dataType: 'json',
   success: function (result) {
     debugs(result);
     var list = result.list;
     if (list.length > 0) {
       var option = "";
       if (parentCode == '00') {
         option += "<option value='00' selected='selected'>学科类</option>"
       } else {
         option += "<option value='00'>学科类</option>";
       }
       $.each(list, function(index, item) {
         if (parentCode == item.majorTypeCode) {
           option += "<option selected='selected' value='" + item.majorTypeCode + "'>" + item.majorTypeName + "</option>";
         } else {
           option += "<option value='" + item.majorTypeCode + "'>" + item.majorTypeName + "</option>";
         }
       });
       $("#majorSubject").html(option);
     }
   }, 
   error: function (xhr) {
     alertError("系统异常，请联系管理员！");// 请求失败遇到异常触发
   }
  });
}
</script>
</body>
</html>
